<template>
	<view class="inventory">
		<xbd-pages-content title="库存查询">
			<template #content>
				<view class="content" :style="'minHeight : ' + windowHeight + 'px;'">
					<view class="choose">

						<xbd-select :carId.sync="type" :visible.sync="visible" :infoList="typeArr">
							<template>
								<view class="select" @click="visible = true">
									<text> {{type || '全部类别'}} </text>
									<image class="image" src="../../static/images/health/right.svg" mode=""></image>
								</view>
							</template>
						</xbd-select>

						<uni-easyinput type="text" v-model="search" placeholder="请输入商品名称或货号查询" />
						<view class="button" @click="clickSearch">
							查库存
						</view>
					</view>

					<uni-list class="ul" :border="false">
						<xbd-goods-card v-for="item in invebtoryList" :key="item._id" :myInfo="item"></xbd-goods-card>
						<xbd-loading-more :status-num="statusNum" :is-load-more="isLoadMore"></xbd-loading-more>
						<xbd-null-list v-if="invebtoryList.length===0"></xbd-null-list>
					</uni-list>
				</view>
			</template>
		</xbd-pages-content>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		Supermarket
	} from '@/api/index.js';
	export default {
		data() {
			return {
				visible: false,
				statusNum: 0,
				isLoadMore: false,
				invebtoryList: [],
				search: '',
				type: '',
				check: {
					type: '',
					keyword: '',
					page: 0,
					perpage: 10,
				},
				typeArr: [
					{
					value: '0',
					label: '全部类别'
				}],
			};
		},
		methods: {
			loadmore() {
				this.queryInfo.page++;
				this.statusNum = 0;
				this.isLoadMore = true;
				this.getList()
			},

			select(res) {
				
				this.type = res.label
			},
			 clickSearch() {
				 if(this.type === '全部类别'){
					this.check.type = ''
				 }else{
					this.check.type = this.type
				 }
				 this.check.keyword = this.search
				 this.check.page = 0
				 this.invebtoryList = []
				 this.getList()
			},
			async getList() {
				try {
					this.$showLoading('加载中');
					const { data: { data } } = await Supermarket.getInventory(this.check);
					uni.hideLoading();
					// console.log(data)
					this.invebtoryList = data;
				} catch (e) {
					uni.hideLoading();
					console.log(e);
				}
			},
			async getClass() {
				try {
					const { data: { list } } = await Supermarket.getInventoryList();
					console.log(list)
					list.forEach((item, index) => {
						this.typeArr.push({
							value: index + 1 + '',
							label: item,
						})
					})
					console.log(this.typeArr)
				} catch (e) {
					uni.hideLoading();
					console.log(e);
				}
			}
		},
		computed: {
			...mapState(['windowHeight']),


		},
		onReachBottom() {
			// console.log(231)
			this.loadmore();
		},
		onLoad() {
			this.getList()
			this.getClass()
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-list {
		padding: 0 50rpx;
	}

	::v-deep .easy-select {
		min-height: 32px;
	}

	::v-deep .uni-input-placeholder {
		text-align: left;
		color: #999999;
	}

	::v-deep .uni-input-input {
		text-align: left;
		color: #999999;
	}
	::v-deep .data-v-abe12412 {
		color: #999999;
		white-space: nowrap;
		font-size: 28rpx;
	}
	::v-deep .data-v-5a1647ca {
		text-align: left;
		white-space: nowrap;
	}

	::v-deep .uni-easyinput__content {
		min-height: 32px;
	}

	::v-deep .uni-input-wrapper {
		text-align: center;
		white-space: nowrap;
	}

	.content {
		padding: 30px 0;
		background-color: #FFFFFF;

		.choose {
			box-sizing: border-box;
			padding: 0 16rpx;
			display: flex;
			margin-bottom: 20px;
		}

		.button {
			height: 32px;
			padding: 0 20rpx;
			background-color: #5473E8;
			border-radius: 4rpx;
			box-sizing: border-box;
			line-height: 32px;
			text-align: center;
			font-size: 28rpx;
			color: #FFFFFF;
			margin-left: 10rpx;
		}

		.select {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 240rpx;
			height: 32px;
			margin-right: 10rpx;
			line-height: 32px;
			border-radius: 8rpx;
			border: 1px solid #E9ECF7;
			box-sizing: border-box;
			padding: 0 20rpx 0 40rpx;
			font-size: 28rpx !important;
			color: #999999;

			.image {
				transform: rotate(90deg);
				width: 38rpx;
				height: 38rpx;
			}
		}

	}
</style>
